package com.epic.followup.controller.app;


import com.alibaba.fastjson.JSON;
import com.epic.followup.model.app.MiniScaleModel;
import com.epic.followup.service.app.MiniScaleService;
import com.epic.followup.service.followup2.BaseUserService;
import com.epic.followup.temporary.DealMessageResponse;
import com.epic.followup.temporary.app.MiniSubmitRequest;
import com.epic.followup.temporary.followup2.session.BaseUserSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author : zmm
 * @version V1.0
 */
@Controller
@RequestMapping("/mini")
public class MiniScaleController {

    private MiniScaleService miniScaleService;
    private BaseUserService baseUserService;

    @Autowired
    public MiniScaleController(MiniScaleService miniScaleService,
                               BaseUserService baseUserService){
        this.miniScaleService = miniScaleService;
        this.baseUserService = baseUserService;
    }

    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public String submitMiniScale(HttpServletRequest request, @RequestBody MiniSubmitRequest miniSubmitRequest){

//        BaseUserSession bus = baseUserService.findBySessionId(request.getHeader("sessionId"));
//        DealMessageResponse dealMessageResponse = new DealMessageResponse();
//
//        MiniScaleModel miniScaleModel = new MiniScaleModel();
//        miniScaleModel.setUserId(bus.getUserId());
//        miniScaleModel.setMiniAnswer(miniSubmitRequest.getAnswer());
//        miniScaleModel.setMiniResult(miniSubmitRequest.getResult());
//        miniScaleModel.setMiniTime(new Date());
//
////        MiniScaleModel miniScaleModel = MiniScaleService.transformMiniRequest(miniSubmitRequest, bus.getUserId());
//
//        // 插入
//        if (miniScaleService.insert(miniScaleModel)){
//            dealMessageResponse.setErrorCode(200);
//            dealMessageResponse.setErrorMsg("succ");
//            return JSON.toJSONString(dealMessageResponse);
//        }else {
//            dealMessageResponse.setErrorCode(505);
//            dealMessageResponse.setErrorMsg("伺服器错误");
//            return JSON.toJSONString(dealMessageResponse);
//        }
        return null;
    }
}
